//
//  CartEditCell.m
//  phmall
//
//  Created by admin on 2017/11/20.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "ShoppingCartEditCell.h"

@implementation ShoppingCartEditCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"NewCell";
    ShoppingCartEditCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ShoppingCartEditCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor=[UIColor whiteColor];
        self.select=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"未选中"]] forState:UIControlStateNormal];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"选中"]] forState:UIControlStateSelected];
        [self.contentView addSubview:self.select];
        
        self.goodsImage=[UIImageView new];
        self.goodsImage.image=[UIImage imageNamed:@"图片"];
        ViewBorderRadius(self.goodsImage, 3, 1, [UIColor colorWithRed:0.93f green:0.94f blue:0.95f alpha:1.00f]);
        self.goodsImage.contentMode=UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.goodsImage];

        self.specification=[UILabel new];
        self.specification.text=@"重量:20g 版本:精装版";
        self.specification.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.specification.font=[UIFont systemFontOfSize:10];
        [self.contentView addSubview:self.specification];
        
        self.edit=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.edit setTitle:Localized(@"删除") forState:UIControlStateNormal];
        self.edit.titleLabel.font=[UIFont systemFontOfSize:15];
        self.edit.backgroundColor=[UIColor colorWithHexString:@"#FF3B31"];
        [self.contentView addSubview:self.edit];

        self.numberButton = [[PPNumberButton alloc]init];
        //设置边框颜色
        self.numberButton.borderColor = [UIColor colorWithHexString:@"#adadad"];
        // 开启抖动动画
        self.numberButton.shakeAnimation = YES;
        // 设置最小值
        self.numberButton.minValue = 1;
        // 设置最大值
        self.numberButton.maxValue = 100;
        // 设置输入框中的字体大小
        self.numberButton.inputFieldFont = 15;
        self.numberButton.increaseTitle = @"＋";
        self.numberButton.decreaseTitle = @"－";
        self.numberButton.delegate=self;
        [self.contentView addSubview:self.numberButton];
        
        self.specification =[[UILabel alloc]init];
        self.specification.font=[UIFont systemFontOfSize:10];
        self.specification.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.specification.numberOfLines=2;
        [self.contentView addSubview:self.specification];
        
        self.line=[UILabel new];
        self.line.backgroundColor=[UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.00f];
        [self.contentView addSubview:self.line];
        
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.select mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).with.offset(5);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    [self.goodsImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).with.offset(5);
        make.bottom.equalTo(self.contentView).with.offset(-5);
        make.left.equalTo(self.select.mas_right).with.offset(5);
        make.width.mas_equalTo(self.goodsImage.mas_height);
    }];
    
    [self.edit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.offset(0);
        make.width.offset(74);
    }];
    
    [self.numberButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsImage.mas_right).offset(15);
        make.top.offset(10);
        make.right.equalTo(self.edit.mas_left).offset(-15);
        make.height.offset(30);
    }];


    [self.specification mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsImage.mas_right).offset(15);
        make.top.equalTo(self.numberButton.mas_bottom).offset(10);
        make.right.equalTo(self.edit.mas_left).offset(-15);
        make.height.offset(30);
    }];
    
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
    
    
}
-(void)setModel:(CartDetailModel *)model{
    _model=model;
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.goods_file1]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.specification.text=model.attr_txt;
    self.numberButton.currentNumber =[model.cart_num doubleValue];
    // 单选按钮设置
    self.select.selected = model.chooseState;
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
